<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('DB列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="config-form">
                <div class="select-list">
                    <input type="hidden" name="pwdHome" id="pwdHome">
                    <ul>
                        <li>
                            表名称：<input type="text" name="tableName"/>
                        </li>
                        <li>
                            表空间名称：<select name="tablespaceName">
                            <option value="">所有</option>
                            <option value="SYSTEM">SYSTEM</option>
                            <option value="USERS">USERS</option>
                        </select>
                        </li>
                        <li>
                            表备注：<input type="text" name="comments"/>
                        </li>
                        <li class="select-time">
                            <label>创建时间： </label>
                            <input type="text" class="time-input" id="sDate" placeholder="开始时间" name="sDate"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="eDate" placeholder="结束时间" name="eDate"/>
                        </li>

                        <li class="select-time">
                            <label>更新时间： </label>
                            <input type="text" class="time-input" id="startDate" placeholder="开始时间" name="startDate"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endDate" placeholder="结束时间" name="endDate"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a  class="btn btn-success" id="perform" shiro:hasPermission="system:config:add">
                <i class="fa fa-plus"></i> 执行
            </a>
            <a class="btn btn-primary single disabled" onclick="edit()" shiro:hasPermission="system:config:edit">
                <i class="fa fa-edit"></i> 编辑
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" class="table text-nowrap"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: use-js"/>

<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:config:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:config:remove')}]];
    var datas = [[${@dict.getType('sys_yes_no')}]];
    var prefix = ctx + "db/config";
    var msg='';
    var flag = false;

    //验证桌面
    var valiHome = function () {
        layer.prompt({title: '请先验证口令', formType: 1}, function(pass, index){
            var pwdHome = $.use.encrypt(pass);
            var data = {"pwdHome":pwdHome}
            var json = JSON.stringify(data);
            var key = {"key":$.use.encrypt(json)}
            $.ajax({
                type: "post",
                url: prefix + "/passwordHome",
                dataType: "json",
                data: key,
                async:false,
                success: function (result) {
                    if (result.code != '0'){
                        flag = false;
                        msg = result.msg;
                    } else {
                        msg = result.msg;
                        flag = true;
                    }
                }
            })
            if (!flag){
                $.modal.alertWarning(msg);
                return;
            }else {
                $("#pwdHome").val(pwdHome);
                layer.close(index);
                list();
            }
        });
    }();

    //初始化表格
    function list() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "参数",
            clickToSelect:true,
            queryParams:queryParams,
            columns: [{
                checkbox: true
            },
                {
                    field: 'TABLE_NAME',
                    title: '表名称',
                    formatter: function(value, row, index) {
                        return value.toLowerCase();
                    }
                },
                {
                    field: 'COMMENTS',
                    title: '表备注',
                    formatter: function(value, row, index) {
                        return value;
                    }
                },
                {
                    field: 'TABLESPACE_NAME',
                    title: '表空间名称'
                },
                {
                    field: 'STATUS',
                    title: '表状态',
                    formatter: function(value, row, index) {
                        if (value == 'VALID'){
                            return "<span style='color: green'>有效</span>";
                        } else {
                            return "<span style='color: green'>无效</span>";
                        }
                    }
                },
                {
                    field: 'CREATE_TIME',
                    title: '创建时间'
                },
                {
                    field: 'UPDATE_TIME',
                    title: '更新时间'
                },
                {
                    field: 'READ_ONLY',
                    title: '是否只读'
                },
                {
                    field: 'USER_STATS',
                    title: '是否有统计'
                },
                {
                    field: 'PARTITIONED',
                    title: '是否分区',
                    align: 'center'
                },
                {
                    field: 'TABLE_LOCK',
                    title: '是否启用表锁'
                },
                {
                    field: 'DEGREE',
                    title: '实例线程数量扫描表'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="find(\'' + row.TABLE_NAME + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    }

    /**
     * 查看信息
     * */
    function find(obj) {
        $.modal.openTab("字段详情",prefix + "/find?TABLE_NAME=" + obj)
    }


    /**
     * 编辑信息
     * */
    function edit() {
        var TABLE_NAME = $.table.selectColumns("TABLE_NAME");
        $.modal.openTab("编辑字段",prefix + "/editView?TABLE_NAME=" + TABLE_NAME)
    }

    function queryParams(params) {
        var search = $.table.queryParams(params);
        search.pwdHome = $("#pwdHome").val();
        return search;
    }


    $("#perform").click(function(){
        var one = '0';
        if ($.common.isEmpty($("#pwdHome").val())){
            $.modal.alertWarning('请先验证首页密码');
            one = '1';
            return;
        }
        layer.prompt({title: '请先验证密码', formType: 1}, function(pass, index){
            var pwd = $.use.encrypt(pass);
            var pwdHome = $("#pwdHome").val();
            var data = {"pwd":pwd,"pwdHome":pwdHome,"one":one}
            var json = JSON.stringify(data);
            var key = {"key":$.use.encrypt(json)}
            $.ajaxSettings.async = false;
            var flag = false;
            var msg = '';
            $.post(prefix + "/pwd",key,function (result) {
                if (result.code != '0'){
                    flag = false;
                    msg = result.msg;
                } else {
                    msg = result.msg;
                    flag = true;
                }
            })
            if (!flag){
                $.modal.alertWarning(msg);
                return;
            }
            layer.close(index);
            $.modal.openTab("执行",prefix + "/perform?pwd=" + pwd + "&pwdHome=" +pwdHome)
        });
    })


</script>
</body>
</html>